import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from '@dfeidao/atom-web/url/refresh';

export default async function a004(fd: IFeidaoAiBrowserComponent) {
	// 保存
	const plan_list_name = fd.data.node.querySelector<HTMLInputElement>('[data-id="plan_list_name"]').value;
	if (!plan_list_name) {
		alert("请添加清单名称");
		return;
	}
	const plan_cla_attr_no1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="plan_cla_attr_no"]');
	const plan_cla_attr_no = plan_cla_attr_no1.value;

	let plan_cla_attr_name = '';
	if (plan_cla_attr_no === '请选择') {
		alert("请选择计划分类属性");
		return;
	} else {
		plan_cla_attr_name = plan_cla_attr_no1.selectedOptions[0].text;
	}
	const plan_type_no1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="plan_type_no"]');
	const plan_type_no = plan_type_no1.value;
	let plan_type_name = '';
	if (plan_type_no === '请选择') {
		alert("请选择计划分类类型");
		return;
	} else {
		plan_type_name = plan_type_no1.selectedOptions[0].text;
	}
	const plan_list_depict = fd.data.node.querySelector<HTMLInputElement>('[data-id="plan_list_depict"]').value;
	if (!plan_list_depict) {
		alert("请添加清单描述");
		return;
	}
	const obj = await nodejs<{ code: 0 | 1; result: string }>('wangju/zj-000004/s003', {

		plan_list_name,
		plan_type_no,
		plan_type_name,
		plan_cla_attr_no,
		plan_cla_attr_name,
		plan_list_depict,
	});
	console.log(obj);
	if (obj.code === 1) {
		alert('添加成功');
		refresh();
	} else {
		alert('添加失败');
	}
}
